<div id="access_modal" class="modal hide fade modal-mini">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h3>门店授权</h3>
	</div>
	<div class="modal-body">
		<div id="tree"></div>
	</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
    	<button class="btn btn-primary" onclick="save_access()">保存</button>
	</div>
</div>

<script type="text/javascript">
$(function(){
	$('#tree').jstree({ 
		core : {
			data : {$data},
			 dblclick_toggle: false
		},
		checkbox : {
			 keep_selected_style : false,
			 three_state: true, // 父级选中自动全选子集
		},
		plugins : [  "checkbox" ]
	});
});

function save_access(){
	var checked = $('#tree').jstree('get_checked', true);
	var store = [];
	for(var i in checked){
		if(checked[i].icon == 'icon-home'){	//门店
			store.push( checked[i].original.real_id );
		}
	}
	
	$.ajax({
		url: '__ACTION__',
		data: {role_id: {$role_id}, store_id: store.join(',')},
		dataType: 'json',
		type: 'post',
		success: function(){
			$('#access_modal').modal('hide');
		}
	});
}
</script>